package LeetCode_225;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2022/10/26 12:09
 */
public class MyStack {
    private final Queue<Integer> queue1 = new LinkedList<>();
    private final Queue<Integer> queue2 = new LinkedList<>();
    private Queue<Integer> readyPutElement = queue1;
    private Queue<Integer> helpQueue = queue1;

    public MyStack(){

    }
    public void push(int x) {
        readyPutElement.offer(x);
    }

    public int pop() {
        int size = readyPutElement.size();
        for (int i = 0; i < size-1; i++) {
            int e = readyPutElement.poll();
            helpQueue.offer(e);
        }

        int ans = readyPutElement.poll();

        Queue<Integer> temp = readyPutElement;
        readyPutElement = helpQueue;
        helpQueue = temp;
        return ans;
    }

    public int top() {
        int size = readyPutElement.size();
        for (int i = 0; i < size-1; i++) {
            int e = readyPutElement.poll();
            helpQueue.offer(e);
        }

        int ans = readyPutElement.poll();
        helpQueue.offer(ans);
        Queue<Integer> temp = readyPutElement;
        readyPutElement = helpQueue;
        helpQueue = temp;
        return ans;
    }

    public boolean empty() {
        return readyPutElement.size() == 0;
    }
}
